package com.example.smartcitydemo.bean

import android.text.Html
import android.text.Spanned
import androidx.recyclerview.widget.DiffUtil
import com.example.smartcitydemo.util.PinyinUtils
import kotlinx.serialization.Serializable
import java.util.*

/**
 * @PACKAGE_NAME: com.example.smartcitydemo.bean
 * @NAME: Caleb.F
 * @DATE: 2021/11/4 8:39
 * @Email: 1919796283@qq.com
 */
/*
* 列表数据基类
* @param T
* @property code Int
* @property msg String
* @property total Int
* @property rows List<T>
* @constructor
*/
@Serializable
data class BaseListResponse<T>(
    val code: Int,
    val msg: String,
    val total: Int = 0,
    val rows: List<T> = mutableListOf(),
)

/**
 * 数据基类，为方便后续封装，
 * 此处使用kotlin-serlization中的默认参数方法解决
 *也可以通过
 */
@Serializable
data class BaseResponse<T>(
    val code: Int,
    val msg: String,
    val data: T? = null,
)


/**
 * 点赞、登录的data class
 * @property result String
 * @constructor
 */
@Serializable
data class SuccessBean(
    val code: Int,
    val msg: String,
    //token可以为null,方便登录请求和点赞的请求共用`data class`
    val token: String? = "success",
)


/**
 *
 * @property id Int
 * @property imgUrl String
 * @property serviceName String
 * @constructor
 */
@Serializable
data class ServiceBean(
    val id: Int,
    val imgUrl: String,
    val serviceName: String,
) {
    companion object diffCallback : DiffUtil.ItemCallback<ServiceBean>() {
        override fun areItemsTheSame(oldItem: ServiceBean, newItem: ServiceBean): Boolean {
            return oldItem.id == newItem.id
        }

        override fun areContentsTheSame(oldItem: ServiceBean, newItem: ServiceBean): Boolean {
            return oldItem.imgUrl == newItem.imgUrl
        }

    }
}

@Serializable
data class NewsTypBean(
    val id: Int,
    val name: String,
)

@Serializable
data class HomeBannerBean(
    val advImg: String = "",
    val id: Int,
)


@Serializable
data class NewsInfo(
    val id: Int,
    val title: String? = "",
    val cover: String? = "",
    val content: String,
    val publishDate: String? = "2021年11月1号",
    val commentNum: Int? = 0,
    val likeNum: Int? = 0,
    val readNum: Int? = 0,
) {
    //有计算属性后续会用
    val contentString = Html.fromHtml(content)
    val likeNumString: String = "喜欢:${likeNum}"
    val readNumString: String = "阅读:${readNum}"
    val commentNumString: String = "评论:${commentNum}"


    companion object diffCallBack : DiffUtil.ItemCallback<NewsInfo>() {
        override fun areItemsTheSame(oldItem: NewsInfo, newItem: NewsInfo): Boolean {
            return oldItem.id == newItem.id
        }

        override fun areContentsTheSame(oldItem: NewsInfo, newItem: NewsInfo): Boolean {
            return oldItem.cover == newItem.cover
        }

    }
}

@Serializable
data class ReplyInfo(
    val id: Int,
    val commentDate: String? = "",
    val content: String? = "",
    val likeNum: Int? = 0,
    val userName: String? = "",
) {
    companion object callback : DiffUtil.ItemCallback<ReplyInfo>() {
        override fun areItemsTheSame(oldItem: ReplyInfo, newItem: ReplyInfo): Boolean {
            return oldItem.id == newItem.id
        }

        override fun areContentsTheSame(oldItem: ReplyInfo, newItem: ReplyInfo): Boolean {
            return oldItem.commentDate == newItem.commentDate
        }

    }
}

@Serializable
data class UseInfo(
    val code: Int,
    val msg: String,
    val user: User? = null,
)

@Serializable
data class User(
    val avatar: String? = "",
    val balance: Double? = 0.0,
    val email: String? = "",
    val idCard: String? = "",
    val nickName: String? = "",
    val phonenumber: String? = "",
    val score: Int? = 0,
    val sex: String? = "0",
    val userId: Int,
    val userName: String? = "",
) {
    val scoreString = "积分剩余：$score"
    val moneyString = "余额：$balance"
}

@Serializable
data class PersonModifyInfo(
    val key: String,
    val value: String,
) {
    companion object callback : DiffUtil.ItemCallback<PersonModifyInfo>() {
        override fun areItemsTheSame(
            oldItem: PersonModifyInfo,
            newItem: PersonModifyInfo,
        ): Boolean {
            return oldItem.key == newItem.key
        }

        override fun areContentsTheSame(
            oldItem: PersonModifyInfo,
            newItem: PersonModifyInfo,
        ): Boolean {
            return oldItem.value == newItem.value
        }

    }
}

@Serializable
data class BusOrderInfo(
    val createTime: String,
    val end: String,
    val id: Int,
    val orderNum: String,
    val path: String,
    val price: Double? = 0.0,
    val start: String,
    val userId: Int,
    val userName: String,
    val userTel: String? = "",
) {

    val orderString: String = "订单号:$orderNum"
    val priceString: String = "价格:$price"
    val userString: String = "乘车人:$userName"
    val teleString = "电话:$userTel"
    val pathString = "线路:$path"

    companion object callback : DiffUtil.ItemCallback<BusOrderInfo>() {
        override fun areItemsTheSame(oldItem: BusOrderInfo, newItem: BusOrderInfo): Boolean {
            return oldItem.id == newItem.id
        }

        override fun areContentsTheSame(oldItem: BusOrderInfo, newItem: BusOrderInfo): Boolean {
            return oldItem.orderNum == newItem.orderNum
        }

    }
}

/**
 *
 * @property content String
 * @property createTime String
 * @property id Int
 * @property title String
 * @property userId Int
 * @constructor
 */
@Serializable
data class ReplyBean(
    val content: String? = "",
    val createTime: String? = "",
    val id: Int,
    val title: String? = "",
    val userId: Int,
) {
    companion object diffCallBack : DiffUtil.ItemCallback<ReplyBean>() {
        override fun areItemsTheSame(oldItem: ReplyBean, newItem: ReplyBean): Boolean {
            return oldItem.id == newItem.id
        }

        override fun areContentsTheSame(oldItem: ReplyBean, newItem: ReplyBean): Boolean {
            return oldItem.createTime == newItem.createTime
        }

    }
}

@Serializable
data class SubWayBannerBean(
    val advImg: String,
)

@Serializable
data class LocationBean(
    val area: String,
    val city: String,
    val location: String,
    val province: String,
)

@Serializable
data class WeatherInfo(
    val air: String,
    val apparentTemperature: String,
    val day: Int,
    val humidity: String,
    val label: String,
    val maxTemperature: String,
    val minTemperature: String,
    val temperature: String,
    val uv: String,
    val weather: String,
)


@Serializable
data class LineDataBean(
    val lineId: Int,
    val lineName: String,
) {
    val sortedName: String = PinyinUtils.getPinyinFirstLetters(lineName).toLowerCase(Locale.CHINA)

    companion object diffCallback : DiffUtil.ItemCallback<LineDataBean>() {
        override fun areItemsTheSame(oldItem: LineDataBean, newItem: LineDataBean): Boolean {
            return oldItem.lineName == newItem.lineName
        }

        override fun areContentsTheSame(oldItem: LineDataBean, newItem: LineDataBean): Boolean {
            return oldItem.lineName == newItem.lineName
        }

    }
}


@Serializable
data class StationDataBean(
    val lines: List<Line>,
    val name: String,
) {

    //拼音的首字母全称
    val initialsOfStationNames
        get() = run { PinyinUtils.getPinyinFirstLetters(name).toLowerCase(Locale.CHINA) }

    //实现去重复
    val distinctList: List<Line>
        get() = lines.distinctBy {
            it.lineName
        }


    companion object diffCallback : DiffUtil.ItemCallback<StationDataBean>() {
        override fun areItemsTheSame(oldItem: StationDataBean, newItem: StationDataBean): Boolean {
            return oldItem.name == newItem.name
        }

        override fun areContentsTheSame(
            oldItem: StationDataBean,
            newItem: StationDataBean,
        ): Boolean {
            return oldItem.lines.size == newItem.lines.size
        }


    }

}

@Serializable
data class Line(
    val lineId: Int,
    val lineName: String,
)


/**
 * 线路起点、终点、开启时间等id
 * @property lineList List<LineDetail>
 * @property stepInfo StepInfo
 * @constructor
 */
@Serializable
data class SubWayStartDetail(
    val lineList: List<LineDetail>,
    val stepInfo: StepInfo,
)

@Serializable
data class LineDetail(
    val id: Int,
    val name: String,
    val end: String,
    val endTime: String,
    val first: String,
    val startTime: String,
) {

    companion object diffCallBack : DiffUtil.ItemCallback<LineDetail>() {
        override fun areItemsTheSame(oldItem: LineDetail, newItem: LineDetail): Boolean {
            return oldItem.id == newItem.id
        }

        override fun areContentsTheSame(oldItem: LineDetail, newItem: LineDetail): Boolean {
            return oldItem.end == newItem.end &&
                    oldItem.first == newItem.first &&
                    oldItem.startTime == newItem.startTime &&
                    oldItem.endTime == newItem.endTime

        }

    }
}


@Serializable
data class StepInfo(
    val crowd: Int,
    val name: String,
)

@Serializable
data class SubWayImage(
    val imgUrl: String,
)

/**
 * 前一个站点信息
 * 后一个站点信息
 * 此处不需要去重复
 * @property currentName String
 * @property lineId Int
 * @property lineName String
 * @property nextStep NextStep
 * @property preStep PreStep
 * @property reachTime Int
 * @constructor
 */
@Serializable
data class CurrentStationDetail(
    val currentName: String,
    val lineId: Int,
    val lineName: String,
    val nextStep: NextStep,
    val preStep: PreStep,
    val reachTime: Int,
) {
    val reachString = "剩余${reachTime}站到达"

    companion object diffCallBack : DiffUtil.ItemCallback<CurrentStationDetail>() {
        override fun areItemsTheSame(
            oldItem: CurrentStationDetail,
            newItem: CurrentStationDetail,
        ): Boolean {
            return oldItem.lineId == newItem.lineId
        }

        override fun areContentsTheSame(
            oldItem: CurrentStationDetail,
            newItem: CurrentStationDetail,
        ): Boolean {
            return oldItem.lineId == newItem.lineId && oldItem.lineName == newItem.lineName
        }

    }
}

@Serializable
data class NextStep(
    val lines: List<Line>,
    val name: String,
) {
    val nextStationName = "下一站：$name"
    val distinctList: List<Line> = lines.distinctBy {
        it.lineName
    }
}


@Serializable
data class PreStep(
    val lines: List<Line>,
    val name: String,
) {
    val previousStationName = "上一站：$name"
    val distinctList: List<Line> = lines.distinctBy {
        it.lineName
    }
}

@Serializable
data class SubWayNoticeBean(
    val content: String,
    val createBy: String = "",
    val createTime: String,
    val id: Int,
    val title: String,
    val updateBy: String = "",
) {
    val htmlString: Spanned
        get() = Html.fromHtml(content)

    companion object diffCallback : DiffUtil.ItemCallback<SubWayNoticeBean>() {
        override fun areItemsTheSame(
            oldItem: SubWayNoticeBean,
            newItem: SubWayNoticeBean,
        ): Boolean {
            return oldItem.id == newItem.id
        }

        override fun areContentsTheSame(
            oldItem: SubWayNoticeBean,
            newItem: SubWayNoticeBean,
        ): Boolean {
            return oldItem.id == newItem.id
        }

    }
}


@Serializable
data class SubWayPassengerNotice(
    val id: Int,
    val content: String,
    val createTime: String,
    val title: String,
    val updateTime: String,
) {
    val htmlContent: Spanned
        get() = Html.fromHtml(content)
}


@Serializable
data class JobTypeBean(
    val id: Int,
    val professionName: String,
)

@Serializable
data class JobListBean(
    val address: String = "",
    val companyId: Int = 1,
    val companyName: String = "",
    val contacts: String = "",
    val professionId: Int = 1,
    val id: Int = 1,
    val name: String = "",
    val need: String = "",
    val obligation: String = "",
    val professionName: String = "",
    val salary: String = "5000",
) {
    val companyNameEx: String = "公司名字：$companyName"
    val contactsEx: String = "联系人：${contacts}"
    val nameEx: String = "职位名称：${name}"
    val needEx: String = "工作要求：${need}"
    val obligationEx: String = "工作职责：${obligation}"
    val salaryEx: String = "工资薪资：$salary"
    val addressEx: String = "工作地址：$address"

    companion object jobCallBack : DiffUtil.ItemCallback<JobListBean>() {
        override fun areItemsTheSame(oldItem: JobListBean, newItem: JobListBean): Boolean {
            return oldItem.id == newItem.id
        }

        override fun areContentsTheSame(oldItem: JobListBean, newItem: JobListBean): Boolean {
            return oldItem.companyId == newItem.companyId && oldItem.professionId == newItem.professionId
        }

    }
}


@Serializable
data class ComPanyDetail(
    val companyName: String = "",
    val id: Int,
    val introductory: String = "",
) {
    val companyNameEx = "公司名字：$companyName"
    val introductoryEx = "公司介绍：$introductory"
}


@Serializable
data class DeliverHistoryBean(
    val id: Int,
    val userId: Int,
    val money: String = "5000",
    val postName: String = "虎牙科技",
    val companyName: String = "虎牙科技",
    val satrTime: String = "2021年7月1日",
) {
    companion object diffCallBack : DiffUtil.ItemCallback<DeliverHistoryBean>() {
        override fun areItemsTheSame(
            oldItem: DeliverHistoryBean,
            newItem: DeliverHistoryBean,
        ): Boolean {
            return oldItem.id == newItem.id
        }

        override fun areContentsTheSame(
            oldItem: DeliverHistoryBean,
            newItem: DeliverHistoryBean,
        ): Boolean {
            return oldItem.id == newItem.id
        }

    }
}

@Serializable
data class ResumeDetailBean(
    val address: String? = "",
    val education: String? = "",
    val experience: String? = "",
    val id: Int,
    val individualResume: String? = "",
    val money: String? = "",
    val mostEducation: String? = "",
    val positionName: String? = "",
) {
    companion object diffCallBack : DiffUtil.ItemCallback<ResumeDetailBean>() {
        override fun areItemsTheSame(
            oldItem: ResumeDetailBean,
            newItem: ResumeDetailBean,
        ): Boolean {
            return oldItem.id == newItem.id
        }

        override fun areContentsTheSame(
            oldItem: ResumeDetailBean,
            newItem: ResumeDetailBean,
        ): Boolean {
            return oldItem.address == newItem.address &&
                    oldItem.education == newItem.education &&
                    oldItem.mostEducation == newItem.mostEducation &&
                    oldItem.experience == newItem.experience &&
                    oldItem.individualResume == newItem.individualResume &&
                    oldItem.money == newItem.money
        }

    }
}

@Serializable
data class ResumePostBean(
    val mostEducation: String,
    val education: String,
    val address: String,
    val experience: String,
    val individualResume: String,
    val money: String,
)

@Serializable
data class ResumeModifyBean(
    val id: Int,
    val address: String,
    val education: String,
    val experience: String,
    val individualResume: String,
    val money: String,
    val mostEducation: String,
)

/**
 * 投递个人简历
 * @property companyId Int
 * @property money String
 * @property postName String
 * @constructor
 */
@Serializable
data class DeliverPostBean(
    val companyId: Int,
    val money: String,
    val postName: String,
)

@Serializable
data class BusListInfo(
    val createTime: String,
    val end: String,
    val endTime: String,
    val first: String,
    val id: Int,
    val mileage: String,
    val name: String,
    val price: Double,
    val startTime: String,
    val updateTime: String = "2021年8月24号"
) {
    val priceString: String
        get() = "$price 元"
    val miledgeString: String
        get() = "$mileage 公里"
}

/**
 * 站点信息查询
 * @property linesId Int
 * @property name String
 * @property sequence Int
 * @property stepsId Int
 * @constructor
 */
@Serializable
data class BusStationData(
    val linesId: Int,
    val name: String,
    val sequence: Int,
    val stepsId: Int,
) {

    companion object DiffCallBack : DiffUtil.ItemCallback<BusStationData>() {
        override fun areItemsTheSame(oldItem: BusStationData, newItem: BusStationData): Boolean {
            return oldItem.stepsId == newItem.stepsId
        }

        override fun areContentsTheSame(oldItem: BusStationData, newItem: BusStationData): Boolean {
            return oldItem.name == newItem.name
        }
    }
}


@Serializable
data class BusOrderResponseBean(
    val code: Int,
    val msg: String,
    val orderNum: String
)


@Serializable
data class SmartBusRequestBean(
    val end: String,
    val path: String,
    val price: String,
    val start: String,
    val status: Int
)




